#pragma comment(linker,"/STACK:100000000")
#include "testlib.h"
#include <stdio.h>
#include <vector>
#include <set>
#define N 50100
using namespace std;
vector <int> m[N];
int u[N];
set <long long> s;
bool dfs(int i)
{
	int j;
	u[i]=1;
	for(j=0; j<m[i].size(); j++)
		if(u[m[i][j]]==1) return 1;
		else if(!u[m[i][j]] && dfs(m[i][j])) return 1;
	u[i]=2;
	return 0;
}
int main(int argc, char * argv[])
{
	registerValidation();
	int n, i, j, k;
	n=inf.readInt(1, 50000, "N"); inf.readSpace();
	k=inf.readInt(0, 50000, "K"); inf.readEoln();
	for(; k--; )
	{
		i=inf.readInt(1, n, "u_i"); inf.readSpace();
		j=inf.readInt(1, n, "u_i"); inf.readEoln();
		ensuref(i!=j, "loops are not allowed");
		m[i].push_back(j);
		if(j<i) swap(i, j);
		ensuref(s.find((long long)i*N+j)==s.end(), "multiple edges are not allowed");
		s.insert((long long)i*N+j);
	}
	inf.readEof();
	for(i=0; i<n; i++)
		ensuref(u[i] || !dfs(i), "loops are not allowed");
	return 0;
}